SELECT
<#list columnList as column>
    <#if column.options?? && (column.options?size > 0)>

        <#list column.options as option>
            <#list option.filters as optionFilter>
                <#if optionFilter.type.code=="column">
                    ${optionFilter.columnName}
                <#elseif optionFilter.type.code=="symbol">
                    ${optionFilter.oper}
                <#elseif optionFilter.type.code=="value">
                    ${optionFilter.value}
                <#elseif optionFilter.type.code=="fun">
                    ${optionFilter.name}
                </#if>
            </#list>
            <#if column.aliasName??>
                as ${column.aliasName}
            <#else>
                as ${column.name}
            </#if>
        </#list>
    <#else>
        ${column.name}
        <#if column.aliasName??>
            as ${column.aliasName}
        </#if>
    </#if>
    <#if column_has_next>
        ,
    </#if>
</#list>
FROM
${tableName}

<#if filterList?? && (filterList?size > 0)>
    where
    <#list filterList as filter>
        <#if filter.type.code=="column">
            ${filter.columnName}
        <#elseif filter.type.code=="symbol">
            ${filter.oper}
        <#elseif filter.type.code=="value">
            ${filter.value}
        <#elseif filter.type.code=="fun">
            ${filter.name}
        </#if>
    </#list>
</#if>

<#if groupList?? && (groupList?size > 0)>
    group by
    <#list groupList as group>
        <#if group.options?? && (group.options?size > 0)>
            <#list group.options as option>
                <#list option.filters as optionFilter>
                    <#if optionFilter.type.code=="column">
                        ${optionFilter.columnName}
                    <#elseif optionFilter.type.code=="symbol">
                        ${optionFilter.oper}
                    <#elseif optionFilter.type.code=="value">
                        ${optionFilter.value}
                    <#elseif optionFilter.type.code=="fun">
                        ${optionFilter.name}
                    </#if>
                </#list>
            </#list>
        <#else>
            ${group.columnName}
        </#if>
        <#if group_has_next>
            ,
        </#if>
    </#list>
</#if>

<#if orderList?? && (orderList?size > 0)>
    order by
    <#list orderList as order>
        ${order.columnName}
        <#if order_has_next>
            ,
        </#if>
    </#list>
</#if>
